﻿using Demo.API.Models;
using Demo.API.Services;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Demo.API.Controllers
{
    [EnableCors("any")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private readonly UserService _userService;

        public TestController(UserService userService)
        {
            _userService = userService;
        }


        [HttpGet]
        public string Get()
        {
            return _userService.GetName();
        }

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string Post(TestPostViewModel model)
        {
            return model.Id + model.Name;

        }

        /// <summary>
        /// 数据发生了改变
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public string Put()
        {
            return "put";
        }

        /// <summary>
        /// 删除请求
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public string Delete()
        {
            return "delete";
        }
    }
}
